import BaseUtil from '@/BaseUtil';
import BuffUtil from '@/BuffUtil';
import STimer from '@/STimer';
import SelectCommon from 'code/Core/Common/SelectCommon';
import TalentBase from 'code/Scripts/Abilities/base/TalentBase';
const desc = `玩家单位每增加1个，所有友军的伤害增加${ColorSafe}2%|r，onTakeDamage降低${ColorSafe}1%|r|n觉醒效果：单位增伤增加至${ColorSafe}3%`;
const art = 'ReplaceableTextures\\CommandButtons\\BTNGarithos.blp';
const name = '多多益善';
const config: TalentConfigModel = {
    id: 'talent_t_TalentMoreBetter',
    name,
    desc,
    art,
    buffType: {
        id: 'buff_t_TalentMoreBetter',
        art,
        name,
        ubertip: desc,
        attribute: {
            物理伤害倍率: 0.02,
            法术伤害倍率: 0.02,
            物理伤害减免: 0.01,
            法术伤害减免: 0.01,
        },
        stackCountMax: -1,
        dur: 2,
        class: '光环',
    },
    buffTypePlus: {
        id: 'buff_t_TalentMoreBetter_plus',
        art,
        name: '多多益善[觉醒]',
        ubertip: `玩家单位每增加1个，所有友军的伤害增加${ColorSafe}3%|r，onTakeDamage降低${ColorSafe}1%|r`,
        attribute: {
            物理伤害倍率: 0.03,
            法术伤害倍率: 0.03,
            物理伤害减免: 0.01,
            法术伤害减免: 0.01,
        },
        stackCountMax: -1,
        dur: 2,
        class: '光环',
    },
};
export default class TalentMoreBetter extends TalentBase {
    static instance: TalentMoreBetter;
    private _providers: unit[] = [];
    private _stimer: STimer;
    constructor(p?: TalentConfigModel) {
        super(p);
        TalentMoreBetter.instance = this;
        this.setTalentConfig(config);
        this.onAddTalent(this.addTalentEffect);
    }
    addTalentEffect<T extends TalentBase = TalentMoreBetter>(u: unit, talent: T) {
        let _this = TalentMoreBetter.instance;
        if (_this._providers.includes(u)) return;
        _this._providers.push(u);
        if (_this._stimer != null) return;
        _this._stimer = BaseUtil.onTimer(1, this.timerEffect);
    }
    timerEffect() {
        let _this = TalentMoreBetter.instance;
        let all = SelectCommon.getAllPlayerAvilableUnits();
        for (let p of _this._providers) {
            if (!IsUnitAliveBJ(p)) continue;
            let { plus } = _this.talentUnEffect(p);
            let id = plus ? _this.buffTypePlus.id : _this.buffType.id;
            for (let a of all) {
                let buff = BuffUtil.getUnitBuff(a, id, p);
                if (buff != null) {
                    buff.stackCount = all.length;
                } else {
                    buff = BuffUtil.addBuff(a, id, p);
                    buff.stackCount = all.length;
                }
            }
        }
        return true;
    }
}
